package com.abocode.aichat.server.context.worker;

import com.abocode.aichat.server.context.ServerRuntimeContext;
import com.abocode.aichat.server.modules.Module;
import com.abocode.aichat.server.modules.MessageStanzaHandlerContext;
import io.netty.channel.Channel;

/**
 * @author guanxf
 */
public abstract class MessageStanzaWorker implements Worker<Channel> {

    protected MessageStanzaHandlerContext stanzaHandlerContext = new MessageStanzaHandlerContext();

    protected ServerRuntimeContext serverRuntimeContext;

    @Override
    public void addModule(Module moduleRegistry) {
        if (serverRuntimeContext == null) {
            throw new NullPointerException("serverRuntimeContext is null");
        }
        moduleRegistry.setRuntimeContext(serverRuntimeContext);
        stanzaHandlerContext.register(moduleRegistry);
    }


    @Override
    public void setServerRuntimeContext(ServerRuntimeContext serverRuntimeContext) {
        if (serverRuntimeContext == null) {
            throw new NullPointerException("serverRuntimeContext is null");
        }
        this.serverRuntimeContext = serverRuntimeContext;
    }

    @Override
    public ServerRuntimeContext getServerRuntimeContext() {
        return serverRuntimeContext;
    }
}
